package main

import (
	"os"
	"os/signal"
	"syscall"
	"test2/mygate"

	"github.com/name5566/leaf/log"
	"github.com/name5566/leaf/network"
)

func main() {
	pid := os.Getpid()
	log.Release("main2 run, pid = %v", pid)
	// var closeSig chan bool

	// var tcpServer *network.TCPServer
	tcpServer := new(network.TCPServer)
	tcpServer.Addr = "0.0.0.0:3000"
	tcpServer.MaxConnNum = 20000
	tcpServer.PendingWriteNum = 100
	tcpServer.LenMsgLen = 4
	tcpServer.MinMsgLen = 0
	tcpServer.MaxMsgLen = 10240
	tcpServer.LittleEndian = true

	tcpServer.NewAgent = func(conn *network.TCPConn) network.Agent {
		a := mygate.NewMyGateNode(conn)
		return a
	}

	if tcpServer != nil {
		tcpServer.Start()
	}
	// <-closeSig

	// close
	c := make(chan os.Signal, 1)
	signal.Notify(c, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGUSR2)
	sig := <-c
	log.Release("Leaf closing down (signal: %v)", sig)

	if tcpServer != nil {
		tcpServer.Close()
	}
}
